Skip to content

jaylydb: ignore undefined participants and sync once per second - #437

Open
1Paul2 wants to merge 3 commits into
JaylyDev:mainfrom
1Paul2:fix/jaylydb-334-311
Open

1Paul2 wants to merge 3 commits into
JaylyDev:mainfrom
1Paul2:fix/jaylydb-334-311

Conversation

@1Paul2

@1Paul2 1Paul2 commented Dec 5, 2026

Copy link
Copy Markdown

Summary

This PR fixes two problems in jaylydb. Each one is in its own commit so they can be reviewed separately.

Commit Issue Change
Ignore undefined scoreboard participants Fixes #334 Skip undefined entries returned by getParticipants()
Sync with the scoreboard once per second Refs #311 Run the background sync every 20 ticks instead of every tick

1. Crash on undefined participants (#334)

Problem. updateParticipants() assumes every element from objective.getParticipants() is a valid ScoreboardIdentity. Sometimes the array contains undefined for an identity that has just been removed, and the loop then throws:

TypeError: cannot read property 'type' of undefined
    at updateParticipants (jaylydb/index.js:108)

This error happens inside the runInterval callback. It interrupts the sync, so the database's local cache can be left cleared or incomplete. The reporter said the error is intermittent, which fits a short gap while an identity is being removed.

Fix. Treat a missing participant like a non-fake-player entry and skip it:

if (!participant || participant.type !== ScoreboardIdentityType.FakePlayer) continue;

2. Full scoreboard re-read on every tick (#311)

Problem. The runInterval in the constructor has no interval argument, so it runs on every tick, 20 times per second. On each run, updateParticipants() clears the local cache and parses every participant again. That cost grows with the size of the database and the number of databases, and you pay it on every tick even when nothing has changed.

Fix. Add a SYNC_INTERVAL constant (20 ticks = 1 second) and pass it to system.runInterval.

Behavior impact:

  • get, set, delete, iteration and the other methods still use the local cache directly, so the script sees no change in behavior.
  • Only changes made to the objective from outside the script (for example, /scoreboard commands) can now take up to one second to show up in the cache.
  • Recovery when the objective is deleted (the SYNC_OK logic) works as before. It now runs on the same one-second interval.

Why "Refs" and not "Fixes". Issue #311 reports a watchdog spike while the database initializes. This change removes the repeated per-tick work. It does not change the single full read in the constructor, so a very large database may still cause a spike at startup. I'd rather leave the issue open for the maintainers to confirm. A follow-up could spread the initial load across several ticks, for example with system.runJob.

Testing

  • tsc --noEmit -p scripts passes with no errors, checked after each commit.
  • I updated index.ts and the generated index.js the same way, so the two files stay in sync.
  • I have not tested this in game. Testing in a world with a large database would help confirm the effect on Jaylydb when initializes makes a watchdog spike warning #311.

Fixes JaylyDev#334.

Before, when the database read the scoreboard, it assumed every entry
returned by getParticipants() was valid. In some cases the game returns an
empty (undefined) entry for an identity that was already removed, and the
script crashed trying to read its type, which stopped the database from
loading its data. Now those empty entries are skipped and the rest of the
data loads normally.
Refs JaylyDev#311.

Before, every open database re-read the whole scoreboard on every game tick
(20 times per second), rebuilding its local copy each time. With large
databases or several of them this used a lot of processing time and could
slow the world down. Now the sync runs every 20 ticks, once per second,
using the new SYNC_INTERVAL constant.

Reads and writes made by the script are not affected, since they use the
local copy directly. Only changes made to the scoreboard from outside the
script (for example, with commands) may take up to one second to appear.

The single full read done when the database is first created is unchanged,
so this reduces the ongoing cost but may not remove the startup spike
reported in the issue on its own.
Before, the two functions changed in this branch had an extra comment above
them marking who made the correction. That note is not useful to the
project and repeated what the inline comments already explain. Now only the
inline comments that describe each fix (JaylyDev#334 and JaylyDev#311) remain.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

jaylydb: TypeError: cannot read property 'type' of undefined

1 participant